<template>
  <view class="detail-page">

    
    <!-- 项目基本信息卡片 -->
    <view class="info-card">
      <view class="card-header">
        <text class="card-title">项目基本信息</text>
      </view>
      <view class="info-grid">
        <view class="info-item">
          <text class="label">项目名称</text>
          <text class="value">{{ projectInfo.project_name || '未知项目' }}</text>
        </view>
        <view class="info-item">
          <text class="label">客户名称</text>
          <text class="value">{{ projectInfo.customer_name || '未知客户' }}</text>
        </view>
        <view class="info-item">
          <text class="label">负责人电话</text>
          <text class="value">{{ projectInfo.manager_phone || '未知' }}</text>
        </view>
        <view class="info-item">
          <text class="label">现场管理人</text>
          <text class="value">{{ projectInfo.site_manager || '未知' }}</text>
        </view>
        <view class="info-item">
          <text class="label">现场负责人电话</text>
          <text class="value">{{ projectInfo.site_manager_phone || '未知' }}</text>
        </view>
        <view class="info-item">
          <text class="label">客户来源</text>
          <text class="value">{{ projectInfo.customer_source || '未知' }}</text>
        </view>
        <view class="info-item">
          <text class="label">客户等级</text>
          <text class="value">{{ projectInfo.customer_level || '未知' }}</text>
        </view>
        <view class="info-item">
          <text class="label">跟进状态</text>
          <text class="value status-badge" :class="{ 'status-active': projectInfo.follow_status === '跟进中', 'status-completed': projectInfo.status === 'contract_uploaded', 'status-error': projectInfo.follow_status === 'error', 'status-finished': projectInfo.status === '已完结' }">
            {{ getStatusText(projectInfo.follow_status, projectInfo.status) }}
          </text>
        </view>
        <view class="info-item">
          <text class="label">项目地址</text>
          <text class="value">{{ projectInfo.input_address || '未知' }}</text>
        </view>
        <view class="info-item">
          <text class="label">生产数量</text>
          <text class="value">{{ projectInfo.production_quantity || '未知' }}</text>
        </view>
        <view class="info-item">
          <text class="label">产品型号</text>
          <text class="value">{{ projectInfo.product_model || '未知' }}</text>
        </view>
        <view class="info-item">
          <text class="label">创建时间</text>
          <text class="value">{{ projectInfo.createtime || '未知' }}</text>
        </view>
      </view>
    </view>

    <!-- 合同信息与结算开票 -->
    <view class="payment-plan-card">
      <view class="card-header">
        <text class="card-title">合同信息与结算开票</text>
      </view>
      
      <!-- 合同信息部分 -->
      <view class="contract-section">
        <view class="section-title">合同信息</view>
        <view class="contract-form">
          <view class="form-item">
            <text class="form-label">合同编号</text>
            <input
              class="form-input"
              :class="{ 'disabled-input': isProjectCompleted }"
              v-model="projectInfo.contract_number"
              placeholder="请输入合同编号"
              :disabled="isProjectCompleted"
            />
          </view>
          <view class="form-item">
            <text class="form-label">合同金额</text>
            <input
              class="form-input"
              :class="{ 'disabled-input': isProjectCompleted }"
              type="digit"
              v-model="projectInfo.contract_money"
              placeholder="请输入合同金额"
              @input="formatAmount('projectInfo.contract_money')"
              :disabled="isProjectCompleted"
            />
          </view>
          <view class="form-item">
            <text class="form-label">合同文件</text>
            <view class="upload-section">
              <view class="upload-btn" :class="{ 'disabled-upload': isProjectCompleted }" @click="!isProjectCompleted && chooseContractFile()" v-if="!projectInfo.contract_file || projectInfo.contract_file.length === 0">
                <text class="upload-icon">+</text>
                <text class="upload-text">{{ isProjectCompleted ? '已完結，無法上傳' : '上传合同文件' }}</text>
              </view>
              <view class="image-list" v-else>
                <view class="image-item" v-for="(img, index) in projectInfo.contract_file" :key="index">
                  <image :src="img" class="preview-img" mode="aspectFit" @click="previewContractFile(img)" />
                  <text class="remove-btn" v-if="!isProjectCompleted" @click="removeContractFile(index)">×</text>
                </view>
                <view class="upload-btn add-more" :class="{ 'disabled-upload': isProjectCompleted }" @click="!isProjectCompleted && chooseContractFile()" v-if="!isProjectCompleted">
                  <text class="upload-icon">+</text>
                  <text class="upload-text">添加更多</text>
                </view>
              </view>
            </view>
          </view>
        </view>
      </view>
      
      <!-- 收款计划部分 -->
      <view class="payment-plan-section">
        <view class="section-title">收款计划</view>

        <!-- 收款计划列表 -->
        <view class="plan-list" v-if="paymentPlans && paymentPlans.length > 0">
          <view class="plan-item" v-for="(plan, index) in paymentPlans" :key="index">
            <view class="plan-header">
              <text class="plan-number">计划 {{ index + 1 }}</text>
              <text class="plan-status" :class="plan.status === '审核中' ? 'pending' : plan.status === '成功' ? 'success' : plan.status === '异常' ? 'error' : plan.status === '逾期' ? 'overdue' : 'pending'">{{ plan.status || '待处理' }}</text>
            </view>
            <!-- 数据展示区域 -->
              <view class="plan-info">
                <view class="info-grid">
                  <view class="info-item">
                    <text class="info-label">设置金额</text>
                  <text class="info-value amount-highlight">¥{{ plan.amount }}</text>
                  </view>
                  <view class="info-item">
                    <text class="info-label">实收金额</text>
                  <text class="info-value received-highlight">¥{{ plan.actualReceivedAmount || '0' }}</text>
                  </view>
                  <view class="info-item">
                    <text class="info-label">收款日期</text>
                    <text class="info-value">
                      <text v-if="plan.paymentTime">{{ plan.paymentTime }}</text>
                      <text v-else-if="plan.createTime">{{ formatDate(plan.createTime) }}</text>
                      <text v-else>未设置</text>
                    </text>
                  </view>
                  <view class="info-item" v-if="plan.content">
                    <text class="info-label">备注</text>
                    <text class="info-value">{{ plan.content }}</text>
                  </view>
                </view>
              </view>

            <!-- 操作按钮区域 -->
            <view class="plan-actions">
                <button class="action-btn edit" :class="{ 'disabled': isProjectCompleted }" @click="!isProjectCompleted && editPlan(plan, index)" :disabled="isProjectCompleted">编辑</button>
              <!-- 删除按钮只有经理端(角色4)才能看到 -->
                <button 
                v-if="userRole === 4"
                  class="action-btn delete" 
                  :class="{ 'disabled': plan.status === '审核中' || isProjectCompleted }"
                  @click="!isProjectCompleted && deletePlan(index)" 
                  :disabled="plan.status === '审核中' || isProjectCompleted"
                >
                删除
                </button>
                <button 
                  class="action-btn exception" 
                  :class="{ 'disabled': isProjectCompleted }"
                  @click="!isProjectCompleted && markPlanAsException(plan, index)"
                  :disabled="isProjectCompleted"
                >
                  异常
                </button>
            </view>
          </view>
        </view>
        
        <view class="empty-plans" v-else>
          <text class="empty-text">暂无收款计划</text>
        </view>
        
        <!-- 收款计划总结 -->
        <view class="plan-summary" v-if="paymentPlans && paymentPlans.length > 0">
          <view class="summary-item">
            <text class="summary-label">收款计划总数</text>
            <text class="summary-value">{{ paymentPlans.length }}</text>
          </view>
          <view class="summary-item">
            <text class="summary-label">实收总金额</text>
            <text class="summary-value highlight">¥{{ netIncomeDisplay }}</text>
          </view>
        </view>
        
        <!-- 收款计划操作按钮 -->
        <view class="plan-actions">
          <button class="add-plan-btn" :class="{ 'disabled': isProjectCompleted }" @click="!isProjectCompleted && showAddPlanModal()" :disabled="isProjectCompleted">{{ isProjectCompleted ? '已完結，無法添加' : '添加收款计划' }}</button>
          <!-- 查看收款计划按钮 - 只在没有数据时显示 -->
          <button 
            v-if="!paymentPlans || paymentPlans.length === 0" 
            class="view-plans-btn" 
            @click="loadPaymentPlans"
          >
            查看收款计划
          </button>
        </view>
      </view>
      
      <!-- 结算开票部分 -->
      <view class="settlement-section">
        <view class="section-title">结算开票</view>
        <view class="settlement-content">
        <view class="form-item">
          <text class="form-label">结算金额</text>
          <input
            class="form-input"
            :class="{ 'disabled-input': isProjectCompleted }"
            type="digit"
            v-model="settlementAmount"
            placeholder="请输入结算金额"
            @input="formatAmount('settlementAmount')"
            :disabled="isProjectCompleted"
          />
        </view>

        <view class="form-item">
          <text class="form-label">需开票金额</text>
          <input
            class="form-input"
            :class="{ 'disabled-input': isProjectCompleted }"
            type="digit"
            v-model="requiredInvoiceAmount"
            placeholder="请输入需开票金额"
            @input="onInvoiceAmountChange"
            :disabled="isProjectCompleted"
          />
        </view>

        <view class="form-item">
          <text class="form-label">结算凭证</text>
          <view class="upload-section">
            <view class="upload-btn" :class="{ 'disabled-upload': isProjectCompleted }" @click="!isProjectCompleted && chooseSettlementVoucher()" v-if="!settlementVoucher || settlementVoucher.length === 0">
              <text class="upload-icon">+</text>
              <text class="upload-text">{{ isProjectCompleted ? '已完結，無法上傳' : '上传结算凭证' }}</text>
            </view>
            <view class="image-list" v-else>
              <view class="image-item" v-for="(img, index) in settlementVoucher" :key="index">
                <image :src="img" class="preview-img" mode="aspectFit" @click="previewSettlementVoucher(img)" />
                <text class="remove-btn" v-if="!isProjectCompleted" @click="removeSettlementVoucher(index)">×</text>
              </view>
              <view class="upload-btn add-more" :class="{ 'disabled-upload': isProjectCompleted }" @click="!isProjectCompleted && chooseSettlementVoucher()" v-if="!isProjectCompleted">
                <text class="upload-icon">+</text>
                <text class="upload-text">添加</text>
              </view>
            </view>
          </view>
        </view>

        <view class="form-item">
          <text class="form-label">已开票金额</text>
          <input
            class="form-input"
            :class="{ 'disabled-input': isProjectCompleted }"
            type="digit"
            v-model="invoicedAmount"
            placeholder="请输入已开票金额"
            @input="onInvoiceAmountChange"
            :disabled="isProjectCompleted"
          />
        </view>

        <view class="form-item">
          <text class="form-label">返现金额</text>
          <input
            class="form-input"
            :class="{ 'disabled-input': isProjectCompleted }"
            type="digit"
            v-model="cashbackAmount"
            placeholder="请输入返现金额"
            @input="formatAmount('cashbackAmount')"
            :disabled="isProjectCompleted"
          />
        </view>

        <view class="form-item">
          <text class="form-label">税收金额</text>
          <input
            class="form-input"
            :class="{ 'disabled-input': isProjectCompleted }"
            type="digit"
            v-model="taxRateAmount"
            placeholder="请输入税收金额"
            @input="formatAmount('taxRateAmount')"
            :disabled="isProjectCompleted"
          />
        </view>

        <view class="form-item">
          <text class="form-label">结算生产量</text>
          <input
            class="form-input"
            :class="{ 'disabled-input': isProjectCompleted }"
            type="digit"
            v-model="settledProductionQuantity"
            placeholder="请输入结算生产量"
            @input="formatAmount('settledProductionQuantity')"
            :disabled="isProjectCompleted"
          />
        </view>

        <view class="form-item">
          <text class="form-label">未结算生产量</text>
          <input
            class="form-input"
            :class="{ 'disabled-input': isProjectCompleted }"
            type="digit"
            v-model="unsettledProductionQuantity"
            placeholder="请输入未结算生产量"
            @input="formatAmount('unsettledProductionQuantity')"
            :disabled="isProjectCompleted"
          />
        </view>

        <view class="form-item">
          <text class="form-label">实收总金额 <text class="auto-calc-tip">（自动计算）</text></text>
          <text class="form-value net-income">¥{{ netIncomeDisplay || '0.00' }}</text>
        </view>

        <view class="form-item">
          <text class="form-label">未收总金额 <text class="auto-calc-tip">（自动计算）</text></text>
          <text class="form-value unpaid-amount">¥{{ unpaidAmountDisplay || '0.00' }}</text>
        </view>

        <view class="form-item">
          <text class="form-label">发票照片</text>
          <view class="upload-section">
            <view class="upload-btn" :class="{ 'disabled-upload': isProjectCompleted }" @click="!isProjectCompleted && chooseInvoiceVoucher()" v-if="!invoiceVoucher || invoiceVoucher.length === 0">
              <text class="upload-icon">+</text>
              <text class="upload-text">{{ isProjectCompleted ? '已完結，無法上傳' : '上传发票照片' }}</text>
            </view>
            <view class="image-list" v-else>
              <view class="image-item" v-for="(img, index) in invoiceVoucher" :key="index">
                <image :src="img" class="preview-img" mode="aspectFit" @click="previewInvoiceVoucher(img)" />
                <text class="remove-btn" v-if="!isProjectCompleted" @click="removeInvoiceVoucher(index)">×</text>
              </view>
              <view class="upload-btn add-more" :class="{ 'disabled-upload': isProjectCompleted }" @click="!isProjectCompleted && chooseInvoiceVoucher()" v-if="!isProjectCompleted">
                <text class="upload-icon">+</text>
                <text class="upload-text">添加</text>
              </view>
            </view>
          </view>
        </view>

        <view class="form-item">
          <text class="form-label">未开票金额 <text class="auto-calc-tip">（自动计算）</text></text>
          <text class="form-value uninvoiced-amount">¥{{ uninvoicedAmountDisplay || '0.00' }}</text>
        </view>
        </view>
      </view>
    </view>



    <!-- 添加收款计划弹窗 -->
    <uni-popup ref="addPlanPopup" type="center" :mask-click="false">
      <view class="add-plan-modal">
        <view class="modal-header">
          <text class="modal-title">{{ isEditing ? '编辑收款计划' : '添加收款计划' }}</text>
          <text class="close-btn" @click="closeAddPlanModal">×</text>
        </view>
        
        <view class="modal-content">
          <view class="form-item">
            <text class="form-label">收款金额</text>
            <input 
              class="form-input" 
              type="digit" 
              v-model="newPlan.amount" 
              placeholder="请输入收款金额"
              @input="onPaymentAmountInput"
            />
          </view>
          
          <view class="form-item">
            <text class="form-label">实收金额</text>
            <input 
              class="form-input" 
              type="digit" 
              v-model="newPlan.actualReceivedAmount" 
              placeholder="请输入实收金额"
              @input="onActualAmountInput"
            />
          </view>
          
          <view class="form-item">
            <text class="form-label">备注</text>
            <input 
              class="form-input" 
              type="text" 
              v-model="newPlan.content" 
              placeholder="请输入备注信息"
            />
          </view>
          
          <view class="form-item">
            <text class="form-label">收款日期</text>
            <picker 
              mode="date" 
              :value="newPlan.paymentDate" 
              @change="onDateChange"
              class="date-picker"
            >
              <view class="picker-text">{{ newPlan.paymentDate || '请选择收款日期' }}</view>
            </picker>
          </view>
          
          <view class="form-item">
            <text class="form-label">收款凭证</text>
            <view class="upload-section">
              <view class="upload-btn" @click="chooseImage" v-if="!newPlan.receipt || newPlan.receipt.length === 0">
                <text class="upload-icon">+</text>
                <text class="upload-text">上传凭证</text>
              </view>
              <view class="image-list" v-else>
                <view class="image-item" v-for="(img, index) in newPlan.receipt" :key="index">
                  <image :src="img" class="preview-img" mode="aspectFit" />
                  <text class="remove-btn" @click="removeImage(index)">×</text>
                </view>
                <view class="upload-btn add-more" @click="chooseImage">
                  <text class="upload-icon">+</text>
                  <text class="upload-text">添加</text>
                </view>
              </view>
            </view>
          </view>
        </view>
        
        <view class="modal-actions">
          <button class="modal-btn cancel" @click="closeAddPlanModal">取消</button>
          <button class="modal-btn confirm" @click="savePaymentPlan">确定</button>
        </view>
      </view>
    </uni-popup>

    <!-- 加载数据按钮 -->
    <view class="action-buttons" v-if="!hasLoadedData">
      <button class="btn load-data" @click="loadProjectData">加载项目数据</button>
    </view>
    
    <!-- 固定在底部的提交审核按钮 -->
    <view class="fixed-submit-btn" v-if="hasLoadedData && !isProjectCompleted">
      <button class="submit-audit-btn" @click="confirmSubmitAudit">提交审核</button>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      projectId: null,
      projectInfo: {
        status: '', // 项目状态
        contract_number: '',
        contract_money: '',
        received_amount: '',
        contract_file: [] // 合同文件图片数组 - 存储多张合同相关图片
      },
      // 结算与开票
      settlementAmount: '',
      requiredInvoiceAmount: '', // 需开票金额
      invoicedAmount: '',
      settlementVoucher: [], // 结算凭证图片数组 - 存储多张结算凭证图片
      invoiceVoucher: [], // 发票照片图片数组 - 存储多张发票照片
      paymentPlans: [],
      isEditing: false,
      editingIndex: -1,
      hasLoadedData: false, // 是否已加载数据
      newPlan: {
        amount: '',
        actualReceivedAmount: '',
        content: '',
        paymentDate: '',
        receipt: [], // 收款计划凭证图片数组 - 存储多张收款凭证图片
        status: 'pending'
      },
      cashbackAmount: '', // 返现金额
      taxRateAmount: '', // 税收金额
      settledProductionQuantity: '', // 结算生产量
      unsettledProductionQuantity: '', // 未结算生产量
      uninvoicedAmount: '', // 未开票金额
      userRole: null, // 用户角色
    }
  },
  onLoad(options) {
    // 获取用户角色
    this.userRole = uni.getStorageSync('user-role');
    console.log('当前用户角色:', this.userRole);
    
    if (options.id) {
      this.projectId = options.id;
      console.log('页面加载，项目ID:', this.projectId);
      // 自动调用接口获取项目详情和收款计划
      this.loadProjectData();
    }
    if (options.data) {
      try {
        const data = JSON.parse(decodeURIComponent(options.data));
        // 只更新已知的属性，避免动态添加新属性
        if (data.project_name !== undefined) this.projectInfo.project_name = data.project_name;
        if (data.customer_name !== undefined) this.projectInfo.customer_name = data.customer_name;
        if (data.manager_phone !== undefined) this.projectInfo.manager_phone = data.manager_phone;
        if (data.site_manager !== undefined) this.projectInfo.site_manager = data.site_manager;
        if (data.site_manager_phone !== undefined) this.projectInfo.site_manager_phone = data.site_manager_phone;
        if (data.customer_source !== undefined) this.projectInfo.customer_source = data.customer_source;
        if (data.customer_level !== undefined) this.projectInfo.customer_level = data.customer_level;
        if (data.follow_status !== undefined) this.projectInfo.follow_status = data.follow_status;
        // 注意：status 應該從接口獲取，這裡不覆蓋
        // if (data.status !== undefined) this.projectInfo.status = data.status;
        if (data.input_address !== undefined) this.projectInfo.input_address = data.input_address;
        if (data.production_quantity !== undefined) this.projectInfo.production_quantity = data.production_quantity;
        if (data.product_model !== undefined) this.projectInfo.product_model = data.product_model;
        if (data.createtime !== undefined) this.projectInfo.createtime = data.createtime;
        if (data.contract_file !== undefined) this.projectInfo.contract_file = data.contract_file;
        if (data.contract_number !== undefined) this.projectInfo.contract_number = data.contract_number;
        if (data.contract_money !== undefined) this.projectInfo.contract_money = data.contract_money;
        if (data.received_amount !== undefined) this.projectInfo.received_amount = data.received_amount;
        
        // 确保数组字段被正确初始化
        if (!Array.isArray(this.projectInfo.contract_file)) {
          this.projectInfo.contract_file = [];
        }
      } catch (error) {
        console.error('解析数据失败:', error);
      }
    }
    
    // 确保所有数组字段都被正确初始化
    if (!Array.isArray(this.settlementVoucher)) {
      this.settlementVoucher = [];
    }
    if (!Array.isArray(this.invoiceVoucher)) {
      this.invoiceVoucher = [];
    }
    if (!Array.isArray(this.paymentPlans)) {
      this.paymentPlans = [];
    }
    if (!Array.isArray(this.newPlan.receipt)) {
      this.newPlan.receipt = [];
    }
    
    // 注意：所有金额字段已在data选项中声明，无需额外初始化
  },
  // 原生下拉刷新
  onPullDownRefresh() {
    // 只刷新项目详情信息，不刷新收款计划
    this.getProjectDetail().then(() => {
      uni.showToast({ title: '刷新成功', icon: 'success' });
    }).catch(() => {
      uni.showToast({ title: '刷新失败', icon: 'none' });
    }).finally(() => {
      uni.stopPullDownRefresh();
    });
  },
  computed: {
    // 判断项目是否已完结
    isProjectCompleted() {
      const isCompleted = this.projectInfo.status === '已完结';
      console.log('项目状态检查:', {
        status: this.projectInfo.status,
        isCompleted: isCompleted
      });
      return isCompleted;
    },
    
    // 计算实收总金额（收款计划中所有实收金额的总和）
    netIncome() {
      try {
        if (!this.paymentPlans || this.paymentPlans.length === 0) {
          return 0;
        }
        
        const totalReceived = this.paymentPlans.reduce((sum, plan) => {
          const actualAmount = parseFloat(plan.actualReceivedAmount) || 0;
          return sum + actualAmount;
        }, 0);
        
        return totalReceived;
      } catch (error) {
        console.error('计算实收总金额时出错:', error);
        return 0;
      }
    },
    netIncomeDisplay() {
      try {
        // 确保netIncome有值，如果没有则返回0.00
        const income = this.netIncome;
        if (income === undefined || income === null || isNaN(income)) {
          return '0.00';
        }
        return income.toFixed(2);
      } catch (error) {
        console.error('格式化实收总金额时出错:', error);
        return '0.00';
      }
    },
    
    // 计算未收总金额（结算金额 - 实收总金额，不小于0）
    unpaidAmount() {
      try {
        const settlement = parseFloat(this.settlementAmount) || 0;
        const received = this.netIncome;
        const value = settlement - received;
        return value < 0 ? 0 : value;
      } catch (error) {
        console.error('计算未收总金额时出错:', error);
        return 0;
      }
    },
    
    unpaidAmountDisplay() {
      try {
        const unpaid = this.unpaidAmount;
        if (unpaid === undefined || unpaid === null || isNaN(unpaid)) {
          return '0.00';
        }
        return unpaid.toFixed(2);
      } catch (error) {
        console.error('格式化未收总金额时出错:', error);
        return '0.00';
      }
    },
    
    // 计算未开票金额（需开票金额 - 已开票金额，不小于0）
    uninvoicedAmountCalculated() {
      try {
        const required = parseFloat(this.requiredInvoiceAmount) || 0;
        const invoiced = parseFloat(this.invoicedAmount) || 0;
        const value = required - invoiced;
        return value < 0 ? 0 : value;
      } catch (error) {
        console.error('计算未开票金额时出错:', error);
        return 0;
      }
    },
    
    uninvoicedAmountDisplay() {
      try {
        const uninvoiced = this.uninvoicedAmountCalculated;
        if (uninvoiced === undefined || uninvoiced === null || isNaN(uninvoiced)) {
          return '0.00';
        }
        return uninvoiced.toFixed(2);
      } catch (error) {
        console.error('格式化未开票金额时出错:', error);
        return '0.00';
      }
    }
  },
  methods: {
    // 获取项目详情
    async getProjectDetail() {
      if (!this.projectId) {
        console.error('项目ID不存在');
        return;
      }
      
      try {
        uni.showLoading({ title: '加载中...' });
        
        const res = await uni.request({
          url: 'https://data.web1995.top/api/project/getProjectDetail',
          method: 'POST',
          data: { id: this.projectId },
          header: {
            'token': uni.getStorageSync('sc-token') || ''
          }
        });
        
        console.log('项目详情接口返回:', res);
        
        if (res.data && res.data.code === 1) {
          const detailData = res.data.data || {};
          // 更新项目信息，只更新已知的属性，避免动态添加新属性
          if (detailData.project_name !== undefined) this.projectInfo.project_name = detailData.project_name;
          if (detailData.customer_name !== undefined) this.projectInfo.customer_name = detailData.customer_name;
          if (detailData.manager_phone !== undefined) this.projectInfo.manager_phone = detailData.manager_phone;
          if (detailData.site_manager !== undefined) this.projectInfo.site_manager = detailData.site_manager;
          if (detailData.site_manager_phone !== undefined) this.projectInfo.site_manager_phone = detailData.site_manager_phone;
          if (detailData.customer_source !== undefined) this.projectInfo.customer_source = detailData.customer_source;
          if (detailData.customer_level !== undefined) this.projectInfo.customer_level = detailData.customer_level;
          if (detailData.follow_status !== undefined) this.projectInfo.follow_status = detailData.follow_status;
          if (detailData.status !== undefined) {
            this.projectInfo.status = detailData.status;
            console.log('更新项目状态:', detailData.status);
          }
          if (detailData.input_address !== undefined) this.projectInfo.input_address = detailData.input_address;
          if (detailData.production_quantity !== undefined) this.projectInfo.production_quantity = detailData.production_quantity;
          if (detailData.product_model !== undefined) this.projectInfo.product_model = detailData.product_model;
          if (detailData.createtime !== undefined) this.projectInfo.createtime = detailData.createtime;
          
          // 保留用户输入的合同信息，除非后端有新的数据
          if (detailData.contract_number !== undefined) this.projectInfo.contract_number = detailData.contract_number;
          if (detailData.contract_money !== undefined) this.projectInfo.contract_money = detailData.contract_money;
          if (detailData.received_amount !== undefined) this.projectInfo.received_amount = detailData.received_amount;
          if (detailData.contract_file !== undefined) {
            if (Array.isArray(detailData.contract_file)) {
              this.projectInfo.contract_file = detailData.contract_file;
            } else if (typeof detailData.contract_file === 'string' && detailData.contract_file) {
              this.projectInfo.contract_file = detailData.contract_file.split(',').filter(url => url.trim());
            }
          }
          
          // 填充结算开票相关数据
          if (detailData.settlement_amount !== undefined) {
            this.settlementAmount = detailData.settlement_amount || '';
          }
          if (detailData.required_invoice_amount !== undefined) {
            this.requiredInvoiceAmount = detailData.required_invoice_amount || '';
          }
          if (detailData.settlement_images !== undefined) {
            // 如果settlement_images是字符串，按逗号分割成数组
            if (typeof detailData.settlement_images === 'string' && detailData.settlement_images) {
              this.settlementVoucher = detailData.settlement_images.split(',').filter(url => url.trim());
            } else if (Array.isArray(detailData.settlement_images)) {
              this.settlementVoucher = detailData.settlement_images;
            }
          }
          if (detailData.invoiced_amount !== undefined) {
            this.invoicedAmount = detailData.invoiced_amount || '';
          }
          if (detailData.uninvoiced_amount !== undefined) {
            this.uninvoicedAmount = detailData.uninvoiced_amount || '';
          }
          if (detailData.invoiced_images !== undefined) {
            // 如果invoiced_images是字符串，按逗号分割成数组
            if (typeof detailData.invoiced_images === 'string' && detailData.invoiced_images) {
              this.invoiceVoucher = detailData.invoiced_images.split(',').filter(url => url.trim());
            } else if (Array.isArray(detailData.invoiced_images)) {
              this.invoiceVoucher = detailData.invoiced_images;
            }
          }
          
          // 新增：填充返现金额和税收金额
          if (detailData.cashback_amount !== undefined) {
            this.cashbackAmount = detailData.cashback_amount || '';
          }
          if (detailData.tax_rate_amount !== undefined) {
            this.taxRateAmount = detailData.tax_rate_amount || '';
          }
          if (detailData.settled_production_quantity !== undefined) {
            this.settledProductionQuantity = detailData.settled_production_quantity || '';
          }
          if (detailData.unsettled_production_quantity !== undefined) {
            this.unsettledProductionQuantity = detailData.unsettled_production_quantity || '';
          }
          
          // 注意：所有金额字段已在data选项中声明，无需额外检查
          
          // 填充合同信息相关数据
          if (detailData.contract_money !== undefined) {
            this.projectInfo.contract_money = detailData.contract_money || '';
          }
          if (detailData.contract_number !== undefined) {
            this.projectInfo.contract_number = detailData.contract_number || '';
          }
          if (detailData.contract_file !== undefined) {
            // 如果contract_file是字符串，按逗号分割成数组
            if (typeof detailData.contract_file === 'string' && detailData.contract_file) {
              this.projectInfo.contract_file = detailData.contract_file.split(',').filter(url => url.trim());
            } else if (Array.isArray(detailData.contract_file)) {
              this.projectInfo.contract_file = detailData.contract_file;
            }
          }
          
          console.log('更新后的项目信息:', this.projectInfo);
          console.log('更新后的结算开票数据:', {
            settlementAmount: this.settlementAmount,
            requiredInvoiceAmount: this.requiredInvoiceAmount,
            settlementVoucher: this.settlementVoucher,
            invoicedAmount: this.invoicedAmount,
            uninvoicedAmount: this.uninvoicedAmount,
            invoiceVoucher: this.invoiceVoucher,
            cashbackAmount: this.cashbackAmount,
            taxRateAmount: this.taxRateAmount
          });
          

          console.log('更新后的合同信息:', {
            contract_money: this.projectInfo.contract_money,
            contract_number: this.projectInfo.contract_number,
            contract_file: this.projectInfo.contract_file
          });
        } else {
          throw new Error(res.data?.msg || '获取项目详情失败');
        }
      } catch (error) {
        console.error('获取项目详情失败:', error);
        uni.showToast({
          title: error.message || '获取项目详情失败',
          icon: 'none'
        });
      } finally {
        uni.hideLoading();
      }
    },
    
    // 获取收款计划列表
    async getProjectPlanList() {
      if (!this.projectId) {
        console.error('项目ID不存在');
        return;
      }
      
      try {
        const res = await uni.request({
          url: 'https://data.web1995.top/api/project/getProjectPlanList',
          method: 'POST',
          data: { id: this.projectId },
          header: {
            'token': uni.getStorageSync('sc-token') || ''
          }
        });
        
        console.log('收款计划列表接口返回:', res);
        
        if (res.data && res.data.code === 1) {
          const planList = res.data.data || [];
          // 根据接口返回的数据结构进行适配
          this.paymentPlans = planList.map(plan => ({
            id: plan.id,
            pid: plan.pid,
            userId: plan.user_id,
            amount: plan.payment_amount || '0',
            actualReceivedAmount: plan.actual_received_amount || '0',
            content: plan.content || '',
            status: plan.status || 'pending',
            images: this.parseImages(plan.images), // 处理图片数据，支持字符串和数组格式
            paymentTime: plan.payment_time || '',
            createTime: plan.createtime,
            updateTime: plan.updatetime,
            deleteTime: plan.deletetime
          }));
          console.log('收款计划列表:', this.paymentPlans);
        } else {
          console.error('获取收款计划列表失败:', res.data?.msg);
        }
      } catch (error) {
        console.error('获取收款计划列表失败:', error);
      }
    },
    
    // 格式化金额显示
    formatMoney(amount) {
      if (!amount && amount !== 0) return '0.00';
      const num = parseFloat(amount);
      if (isNaN(num)) return '0.00';
      return num.toFixed(2).replace(/\B(?=(\d{3})+(?!\d))/g, ',');
    },
    
    // 获取状态文本
    getStatusText(followStatus, status) {
      if (status === '已完结') {
        return '已完结';
      } else if (status === 'contract_uploaded') {
        return '已签约';
      } else if (followStatus === '跟进中') {
        return '跟进中';
      } else if (followStatus === 'error') {
        return '异常';
      } else {
        return '跟进中';
      }
    },
    
    // 初始化收款计划数据
    initPaymentPlans() {
      // 不自动获取收款计划数据，只在用户主动操作时获取
      console.log('初始化收款计划数据，但不自动调用接口');
    },
    
    // 加载项目数据（用户主动触发）
    async loadProjectData() {
      if (!this.projectId) {
        uni.showToast({
          title: '项目ID不存在',
          icon: 'none'
        });
        return;
      }
      
      try {
        uni.showLoading({ title: '加载项目数据中...' });
        
        // 同时加载项目详情和收款计划
        await Promise.all([
          this.getProjectDetail(),
          this.getProjectPlanList()
        ]);
        
        this.hasLoadedData = true;
        console.log('数据加载完成，最终项目状态:', this.projectInfo.status);
        console.log('isProjectCompleted:', this.isProjectCompleted);
        uni.showToast({
          title: '数据加载完成',
          icon: 'success'
        });
      } catch (error) {
        console.error('加载项目数据失败:', error);
        uni.showToast({
          title: '数据加载失败',
          icon: 'none'
        });
      } finally {
        uni.hideLoading();
      }
    },
    
    // 用户主动查看收款计划时调用
    async loadPaymentPlans() {
      if (!this.projectId) {
        uni.showToast({
          title: '项目ID不存在',
          icon: 'none'
        });
        return;
      }
      
      try {
        uni.showLoading({ title: '加载收款计划中...' });
        await this.getProjectPlanList();
        uni.showToast({
          title: '收款计划加载完成',
          icon: 'success'
        });
      } catch (error) {
        console.error('加载收款计划失败:', error);
        uni.showToast({
          title: '加载收款计划失败',
          icon: 'none'
        });
      } finally {
        uni.hideLoading();
      }
    },
    

    
    // 显示添加收款计划弹窗
    showAddPlanModal() {
      this.isEditing = false;
      this.editingIndex = -1;
      this.resetNewPlan();
      console.log('添加收款计划弹窗打开，重置后的数据:', this.newPlan);
      this.$refs.addPlanPopup.open();
    },
    
    // 关闭添加收款计划弹窗
    closeAddPlanModal() {
      this.$refs.addPlanPopup.close();
      this.resetNewPlan();
    },
    
    // 重置新计划数据
    resetNewPlan() {
      this.newPlan = {
        amount: '',
        actualReceivedAmount: '',
        content: '',
        paymentDate: '',
        receipt: [],
        status: 'pending'
      };
    },
    
    // 日期选择器变化
    onDateChange(e) {
      this.newPlan.paymentDate = e.detail.value;
    },
    
    // 选择收款计划凭证图片 - 支持多张图片上传
    async chooseImage() {
      uni.chooseImage({
        count: 9, // 最多选择9张图片
        sizeType: ['compressed'],
        sourceType: ['album', 'camera'],
        success: async (res) => {
          try {
            uni.showLoading({ title: '上传收款凭证中...' });
            
            // 上传所有选择的收款计划凭证图片到统一接口
            const uploadPromises = res.tempFilePaths.map(filePath => {
              return new Promise((resolve, reject) => {
                uni.uploadFile({
                  url: 'https://data.web1995.top/api/common/upload',
                  filePath: filePath,
                  name: 'file',
                  success: (uploadRes) => {
                    try {
                      const result = JSON.parse(uploadRes.data);
                      if (result.code === 1 && result.data && result.data.fullurl) {
                        resolve(result.data.fullurl);
                      } else {
                        reject(result.msg || '上传失败');
                      }
                    } catch (e) {
                      reject('上传失败');
                    }
                  },
                  fail: (err) => {
                    reject('上传失败：' + err.errMsg);
                  }
                });
              });
            });
            
            const urls = await Promise.all(uploadPromises);
            
            // 将上传成功的收款计划凭证图片URL添加到newPlan.receipt数组中
            this.newPlan.receipt = this.newPlan.receipt.concat(urls);
            
            uni.showToast({ title: '收款凭证上传成功', icon: 'success' });
          } catch (error) {
            console.error('收款凭证上传失败:', error);
            uni.showToast({ title: '收款凭证上传失败', icon: 'none' });
          } finally {
            uni.hideLoading();
          }
        }
      });
    },

    // 选择结算凭证图片 - 支持多张图片上传
    async chooseSettlementVoucher() {
      uni.chooseImage({
        count: 9, // 最多选择9张图片
        sizeType: ['compressed'],
        sourceType: ['album', 'camera'],
        success: async (res) => {
          try {
            uni.showLoading({ title: '上传结算凭证中...' });
            
            // 上传所有选择的结算凭证图片到统一接口
            const uploadPromises = res.tempFilePaths.map(filePath => {
              return new Promise((resolve, reject) => {
                uni.uploadFile({
                  url: 'https://data.web1995.top/api/common/upload',
                  filePath: filePath,
                  name: 'file',
                  success: (uploadRes) => {
                    try {
                      const result = JSON.parse(uploadRes.data);
                      if (result.code === 1 && result.data && result.data.fullurl) {
                        resolve(result.data.fullurl);
                      } else {
                        reject(result.msg || '上传失败');
                      }
                    } catch (e) {
                      reject('上传失败');
                    }
                  },
                  fail: (err) => {
                    reject('上传失败：' + err.errMsg);
                  }
                });
              });
            });
            
            const urls = await Promise.all(uploadPromises);
            
            // 将上传成功的结算凭证图片URL添加到settlementVoucher数组中
            this.settlementVoucher = this.settlementVoucher.concat(urls);
            
            uni.showToast({ title: '结算凭证上传成功', icon: 'success' });
          } catch (error) {
            console.error('结算凭证上传失败:', error);
            uni.showToast({ title: '结算凭证上传失败', icon: 'none' });
          } finally {
            uni.hideLoading();
          }
        }
      });
    },
    removeSettlementVoucher(index) {
      this.settlementVoucher.splice(index, 1);
    },
    previewSettlementVoucher(img) {
      if (this.settlementVoucher && this.settlementVoucher.length > 0) {
        uni.previewImage({ 
          urls: this.settlementVoucher,
          current: img 
        });
      }
    },

    // 选择发票照片 - 支持多张图片上传
    async chooseInvoiceVoucher() {
      uni.chooseImage({
        count: 9, // 最多选择9张图片
        sizeType: ['compressed'],
        sourceType: ['album', 'camera'],
        success: async (res) => {
          try {
            uni.showLoading({ title: '上传发票照片中...' });
            
            // 上传所有选择的发票照片到统一接口
            const uploadPromises = res.tempFilePaths.map(filePath => {
              return new Promise((resolve, reject) => {
                uni.uploadFile({
                  url: 'https://data.web1995.top/api/common/upload',
                  filePath: filePath,
                  name: 'file',
                  success: (uploadRes) => {
                    try {
                      const result = JSON.parse(uploadRes.data);
                      if (result.code === 1 && result.data && result.data.fullurl) {
                        resolve(result.data.fullurl);
                      } else {
                        reject(result.msg || '上传失败');
                      }
                    } catch (e) {
                      reject('上传失败');
                    }
                  },
                  fail: (err) => {
                    reject('上传失败：' + err.errMsg);
                  }
                });
              });
            });
            
            const urls = await Promise.all(uploadPromises);
            
            // 将上传成功的发票照片URL添加到invoiceVoucher数组中
            this.invoiceVoucher = this.invoiceVoucher.concat(urls);
            
            uni.showToast({ title: '发票照片上传成功', icon: 'success' });
          } catch (error) {
            console.error('发票照片上传失败:', error);
            uni.showToast({ title: '发票照片上传失败', icon: 'none' });
          } finally {
            uni.hideLoading();
          }
        }
      });
    },
    removeInvoiceVoucher(index) {
      this.invoiceVoucher.splice(index, 1);
    },
    previewInvoiceVoucher(img) {
      if (this.invoiceVoucher && this.invoiceVoucher.length > 0) {
        uni.previewImage({ 
          urls: this.invoiceVoucher,
          current: img 
        });
      }
    },
    
    // 选择合同文件 - 支持多张图片上传
    async chooseContractFile() {
      uni.chooseImage({
        count: 9, // 最多选择9张图片
        sizeType: ['compressed'],
        sourceType: ['album', 'camera'],
        success: async (res) => {
          try {
            uni.showLoading({ title: '上传合同文件中...' });
            
            // 上传所有选择的合同文件到统一接口
            const uploadPromises = res.tempFilePaths.map(filePath => {
              return new Promise((resolve, reject) => {
                uni.uploadFile({
                  url: 'https://data.web1995.top/api/common/upload',
                  filePath: filePath,
                  name: 'file',
                  success: (uploadRes) => {
                    try {
                      const result = JSON.parse(uploadRes.data);
                      if (result.code === 1 && result.data && result.data.fullurl) {
                        resolve(result.data.fullurl);
                      } else {
                        reject(result.msg || '上传失败');
                      }
                    } catch (e) {
                      reject('上传失败');
                    }
                  },
                  fail: (err) => {
                    reject('上传失败：' + err.errMsg);
                  }
                });
              });
            });
            
            const urls = await Promise.all(uploadPromises);
            
            // 将上传成功的合同文件URL添加到projectInfo.contract_file数组中
            this.projectInfo.contract_file = this.projectInfo.contract_file.concat(urls);
            
            uni.showToast({ title: '合同文件上传成功', icon: 'success' });
          } catch (error) {
            console.error('合同文件上传失败:', error);
            uni.showToast({ title: '合同文件上传失败', icon: 'none' });
          } finally {
            uni.hideLoading();
          }
        }
      });
    },
    
    // 移除合同文件
    removeContractFile(index) {
      this.projectInfo.contract_file.splice(index, 1);
    },
    
    // 预览合同文件
    previewContractFile(img) {
      if (this.projectInfo.contract_file && this.projectInfo.contract_file.length > 0) {
        uni.previewImage({ 
          urls: this.projectInfo.contract_file,
          current: img 
        });
      }
    },
    
    // 移除图片
    removeImage(index) {
      this.newPlan.receipt.splice(index, 1);
    },
    
    // 保存收款计划
    async savePaymentPlan() {
      // 验证必填字段
      if (!this.newPlan.amount) {
        uni.showToast({
          title: '请输入收款金额',
          icon: 'none'
        });
        return;
      }
      
      if (!this.newPlan.paymentDate) {
        uni.showToast({
          title: '请选择收款日期',
          icon: 'none'
        });
        return;
      }
      
      console.log('保存收款计划，当前数据:', {
        amount: this.newPlan.amount,
        actualReceivedAmount: this.newPlan.actualReceivedAmount,
        isEditing: this.isEditing
      });
      
      try {
        uni.showLoading({ title: '保存中...' });
        
        if (this.isEditing) {
          // 编辑模式 - 调用编辑接口
          const editParams = {
            id: this.newPlan.id,
            pid: this.projectId,
            payment_amount: this.newPlan.amount,
            actual_received_amount: this.newPlan.actualReceivedAmount || '0',
            content: this.newPlan.content || '',
            images: this.newPlan.receipt.join(','), // 将图片数组转换为逗号分隔的字符串
            payment_time: this.newPlan.paymentDate
          };
          
          console.log('编辑收款计划参数:', editParams);
          
          const editRes = await uni.request({
            url: 'https://data.web1995.top/api/project/editProjectPlan',
            method: 'POST',
            data: editParams,
            header: {
              'token': uni.getStorageSync('sc-token') || ''
            }
          });
          
          console.log('编辑收款计划接口返回:', editRes);
          
          if (editRes.statusCode === 200 && editRes.data && editRes.data.code === 1) {
            // 编辑成功，更新本地数据
            this.paymentPlans[this.editingIndex] = {
              id: this.newPlan.id,
              pid: this.newPlan.pid,
              userId: this.newPlan.userId,
              amount: this.newPlan.amount,
              actualReceivedAmount: this.newPlan.actualReceivedAmount,
              content: this.newPlan.content,
              status: this.newPlan.status,
              images: this.newPlan.receipt,
              paymentTime: this.newPlan.paymentDate,
              createTime: this.newPlan.createTime,
              updateTime: this.newPlan.updateTime,
              deleteTime: this.newPlan.deleteTime
            };
            this.closeAddPlanModal();
            uni.showToast({
              title: '编辑成功',
              icon: 'success'
            });
            // 刷新收款计划列表
            this.getProjectPlanList();
          } else {
            throw new Error(editRes.data?.msg || '编辑失败');
          }
        } else {
          // 添加模式 - 调用添加接口
          const addParams = {
            pid: this.projectId,
            payment_amount: this.newPlan.amount,
            actual_received_amount: this.newPlan.actualReceivedAmount || '0',
            content: this.newPlan.content || '',
            payment_time: this.newPlan.paymentDate,
            images: this.newPlan.receipt.join(',') // 将图片数组转换为逗号分隔的字符串
          };
          
          console.log('添加收款计划参数:', addParams);
          
          const addRes = await uni.request({
            url: 'https://data.web1995.top/api/project/addProjectPlan',
            method: 'POST',
            data: addParams,
            header: {
              'token': uni.getStorageSync('sc-token') || ''
            }
          });
          
          console.log('添加收款计划接口返回:', addRes);
          
          if (addRes.statusCode === 200 && addRes.data && addRes.data.code === 1) {
            // 添加成功，更新本地数据
            this.paymentPlans.push({
              id: this.newPlan.id,
              pid: this.newPlan.pid,
              userId: this.newPlan.userId,
              amount: this.newPlan.amount,
              actualReceivedAmount: this.newPlan.actualReceivedAmount,
              content: this.newPlan.content,
              status: this.newPlan.status,
              images: this.newPlan.receipt,
              paymentTime: this.newPlan.paymentDate,
              createTime: this.newPlan.createTime,
              updateTime: this.newPlan.updateTime,
              deleteTime: this.newPlan.deleteTime
            });
            this.closeAddPlanModal();
            uni.showToast({
              title: '添加成功',
              icon: 'success'
            });
            // 刷新收款计划列表
            this.getProjectPlanList();
          } else {
            throw new Error(addRes.data?.msg || '添加失败');
          }
        }
      } catch (error) {
        console.error('保存收款计划失败:', error);
        uni.showToast({
          title: error.message || '保存失败',
          icon: 'none'
        });
      } finally {
        uni.hideLoading();
      }
    },
    
    // 编辑计划
    editPlan(plan, index) {
      this.isEditing = true;
      this.editingIndex = index;
      // 只复制已知的属性，避免动态添加新属性
      this.newPlan = {
        id: plan.id,
        pid: plan.pid,
        userId: plan.userId,
        amount: plan.amount || plan.payment_amount || '',
        actualReceivedAmount: plan.actualReceivedAmount || plan.actual_received_amount || '',
        content: plan.content || '',
        paymentDate: plan.paymentTime || plan.payment_time || '',
        receipt: this.parseImages(plan.images || plan.receipt),
        status: plan.status || 'pending'
      };
      this.$refs.addPlanPopup.open();
    },
    
    // 删除计划
    deletePlan(index) {
      const plan = this.paymentPlans[index];
      
      // 检查状态，审核中的不能删除
      if (plan.status === '审核中') {
        uni.showToast({
          title: '审核中的收款计划不能删除',
          icon: 'none'
        });
        return;
      }
      
      uni.showModal({
        title: '确认删除',
        content: '确定要删除这个收款计划吗？',
        success: (res) => {
          if (res.confirm) {
            this.paymentPlans.splice(index, 1);
            uni.showToast({
              title: '删除成功',
              icon: 'success'
            });
          }
        }
      });
    },
    
    // 确认提交审核
    confirmSubmitAudit() {
      uni.showModal({
        title: '确认提交审核',
        content: '确定要提交项目进行审核吗？提交后将无法修改。',
        confirmText: '确定提交',
        cancelText: '取消',
        success: (res) => {
          if (res.confirm) {
            this.submitForAudit();
          }
        }
      });
    },
    
    // 提交审核
    async submitForAudit() {
      if (!this.projectId) {
        uni.showToast({
          title: '项目ID不存在',
          icon: 'none'
        });
        return;
      }
      
            try {
              uni.showLoading({ title: '提交审核中...' });
              
              // 第一步：调用editProjectByFinance接口
              const editRes = await uni.request({
                url: 'https://data.web1995.top/api/project/editProjectByFinance',
                method: 'POST',
                data: {
                  id: this.projectId,
                  // 合同信息
                  contract_file: this.projectInfo.contract_file.join(','), // 合同文件图片 - 逗号分隔的字符串
                  contract_money: this.projectInfo.contract_money || 0, // 合同金额
                  contract_number: this.projectInfo.contract_number || '', // 合同编号
                  // 结算开票信息
                  settlement_amount: this.settlementAmount || 0,
                  required_invoice_amount: this.requiredInvoiceAmount || 0, // 需开票金额
                  settlement_images: this.settlementVoucher.join(','), // 结算凭证图片 - 逗号分隔的字符串
                  invoiced_amount: this.invoicedAmount || 0,
                  invoiced_images: this.invoiceVoucher.join(','), // 发票照片 - 逗号分隔的字符串
                  uninvoiced_amount: this.uninvoicedAmountCalculated || 0, // 未开票金额（自动计算）
                  // 新增字段
                  cashback_amount: this.cashbackAmount || 0, // 返现金额
                  tax_rate_amount: this.taxRateAmount || 0, // 税收金额
                  settled_production_quantity: this.settledProductionQuantity || 0, // 结算生产量
                  unsettled_production_quantity: this.unsettledProductionQuantity || 0, // 未结算生产量
                },
                header: {
                  'token': uni.getStorageSync('sc-token') || ''
                }
              });
              
              console.log('editProjectByFinance接口返回:', editRes);
              
              if (editRes.data && editRes.data.code === 1) {
                // 第一步成功，继续第二步
                console.log('第一步成功，开始第二步');
                
                // 第二步：调用submitProject接口
                const submitRes = await uni.request({
                  url: 'https://data.web1995.top/api/project/submitProject',
                  method: 'POST',
                  data: { id: this.projectId },
                  header: {
                    'token': uni.getStorageSync('sc-token') || ''
                  }
                });
                
                console.log('submitProject接口返回:', submitRes);
                
                if (submitRes.data && submitRes.data.code === 1) {
                  uni.showToast({
                    title: '已提交审核',
                    icon: 'success'
                  });
                  
                  // 延迟返回上一页
                  setTimeout(() => {
                    uni.navigateBack();
                  }, 1500);
                } else {
                  throw new Error(submitRes.data?.msg || '第二步提交审核失败');
                }
              } else {
                throw new Error(editRes.data?.msg || '第一步编辑项目失败');
              }
            } catch (error) {
              console.error('提交审核失败:', error);
              uni.showToast({
                title: error.message || '提交审核失败',
                icon: 'none'
              });
            } finally {
              uni.hideLoading();
            }
    },
    
    // 标记为异常
    markAsException() {
      uni.showModal({
        title: '确认标记',
        content: '确定要将此项目标记为异常吗？',
        success: (res) => {
          if (res.confirm) {
            // 这里可以调用标记异常的接口
            uni.showToast({
              title: '已标记为异常',
              icon: 'success'
            });
            
            // 延迟返回上一页
            setTimeout(() => {
              uni.navigateBack();
            }, 1500);
          }
        }
      });
    },

    // 标记收款计划为异常
    markPlanAsException(plan, index) {
      uni.showModal({
        title: '确认标记',
        content: `确定要将此收款计划标记为异常吗？`,
        success: async (res) => {
          if (res.confirm) {
            try {
              uni.showLoading({ title: '标记中...' });
              const markRes = await uni.request({
                url: 'https://data.web1995.top/api/project/setProjectPlan',
                method: 'POST',
                data: {
                  id: plan.id, // 当前收款计划这条数据的id
                  pid: this.projectId // 项目id
                },
                header: {
                  'token': uni.getStorageSync('sc-token') || ''
                }
              });
              console.log('setProjectPlan接口返回:', markRes);
              if (markRes.data && markRes.data.code === 1) {
                this.paymentPlans[index].status = '异常';
                uni.showToast({
                  title: '已标记为异常',
                  icon: 'success'
                });
                this.getProjectPlanList(); // 刷新列表以更新状态
              } else {
                throw new Error(markRes.data?.msg || '标记失败');
              }
            } catch (error) {
              console.error('标记收款计划异常失败:', error);
              uni.showToast({
                title: error.message || '标记失败',
                icon: 'none'
              });
            } finally {
              uni.hideLoading();
            }
          }
        }
      });
    },
    

    
    // 格式化时间戳
    formatDate(timestamp) {
      if (!timestamp) return '';
      const date = new Date(timestamp * 1000);
      return date.toLocaleDateString('zh-CN');
    },
    
    // 格式化金额输入
    formatAmount(fieldName) {
      let value;
      
      // 处理嵌套对象属性（如 projectInfo.contract_money）
      if (fieldName.includes('.')) {
        const parts = fieldName.split('.');
        const obj = this[parts[0]];
        value = obj[parts[1]] || '';
      } else {
        value = this[fieldName] || '';
      }
      
      // 移除非数字字符（保留小数点）
      value = value.toString().replace(/[^\d.]/g, '');
      
      // 确保只有一个小数点
      const parts = value.split('.');
      if (parts.length > 2) {
        value = parts[0] + '.' + parts.slice(1).join('');
      }
      
      // 限制小数点后两位
      if (parts.length === 2 && parts[1].length > 2) {
        value = parts[0] + '.' + parts[1].substring(0, 2);
      }
      
      // 更新字段值
      if (fieldName.includes('.')) {
        const parts = fieldName.split('.');
        this[parts[0]][parts[1]] = value;
      } else {
        this[fieldName] = value;
      }
    },

    // 处理开票金额输入变化，触发未开票金额的重新计算
    onInvoiceAmountChange() {
      // Vue的响应式系统会自动触发计算属性的重新计算
      // 这里可以添加额外的处理逻辑，比如格式化输入
      this.$nextTick(() => {
        // 确保DOM更新后，计算属性已经重新计算
        // 未开票金额会自动重新计算并显示
      });
    },
    
    // 解析图片数据，支持字符串和数组格式
    parseImages(images) {
      if (!images) {
        return [];
      }
      
      // 如果已经是数组，直接返回
      if (Array.isArray(images)) {
        return images;
      }
      
      // 如果是字符串，按逗号分割并过滤空值
      if (typeof images === 'string') {
        return images.split(',').filter(url => url.trim() !== '');
      }
      
      // 其他情况返回空数组
      return [];
    },
    
    // 监听收款金额输入
    onPaymentAmountInput(e) {
      console.log('收款金额输入事件:', e.detail.value);
      console.log('当前newPlan数据:', this.newPlan);
      // 确保不会自动填充实收金额
      // 这里不应该有任何自动填充逻辑
    },
    
    // 监听实收金额输入
    onActualAmountInput(e) {
      console.log('实收金额输入事件:', e.detail.value);
      console.log('当前newPlan数据:', this.newPlan);
    },
    
    // 确认提交审核
    confirmSubmitAudit() {
      uni.showModal({
        title: '确认提交审核',
        content: '确定要提交项目进行审核吗？提交后将无法修改。',
        confirmText: '确定提交',
        cancelText: '取消',
        success: (res) => {
          if (res.confirm) {
            this.submitForAudit();
          }
        }
      });
    },
    
    // 提交审核
    async submitForAudit() {
      if (!this.projectId) {
        uni.showToast({
          title: '项目ID不存在',
          icon: 'none'
        });
        return;
      }
      
      try {
        uni.showLoading({ title: '提交审核中...' });
        
        // 第一步：调用editProjectByFinance接口
        const editRes = await uni.request({
                url: 'https://data.web1995.top/api/project/editProjectByFinance',
                method: 'POST',
                data: {
                  id: this.projectId,
                  // 合同信息
                  contract_file: this.projectInfo.contract_file.join(','), // 合同文件图片 - 逗号分隔的字符串
                  contract_money: this.projectInfo.contract_money || 0, // 合同金额
                  contract_number: this.projectInfo.contract_number || '', // 合同编号
                  // 结算开票信息
                  settlement_amount: this.settlementAmount || 0,
                  required_invoice_amount: this.requiredInvoiceAmount || 0, // 需开票金额
                  settlement_images: this.settlementVoucher.join(','), // 结算凭证图片 - 逗号分隔的字符串
                  invoiced_amount: this.invoicedAmount || 0,
                  invoiced_images: this.invoiceVoucher.join(','), // 发票照片 - 逗号分隔的字符串
                  uninvoiced_amount: this.uninvoicedAmountCalculated || 0, // 未开票金额（自动计算）
                  // 新增字段
                  cashback_amount: this.cashbackAmount || 0, // 返现金额
                  tax_rate_amount: this.taxRateAmount || 0, // 税收金额
                  settled_production_quantity: this.settledProductionQuantity || 0, // 结算生产量
                  unsettled_production_quantity: this.unsettledProductionQuantity || 0, // 未结算生产量
                },
                header: {
                  'token': uni.getStorageSync('sc-token') || ''
                }
              });
              
              console.log('editProjectByFinance接口返回:', editRes);
              
              if (editRes.data && editRes.data.code === 1) {
                // 第一步成功，继续第二步
                console.log('第一步成功，开始第二步');
                
                // 第二步：调用submitProject接口
                const submitRes = await uni.request({
                  url: 'https://data.web1995.top/api/project/submitProject',
                  method: 'POST',
                  data: { id: this.projectId },
                  header: {
                    'token': uni.getStorageSync('sc-token') || ''
                  }
                });
                
                console.log('submitProject接口返回:', submitRes);
                
                if (submitRes.data && submitRes.data.code === 1) {
      uni.showToast({
                    title: '已提交审核',
                    icon: 'success'
                  });
                  
                  // 延迟返回上一页
                  setTimeout(() => {
                    uni.navigateBack();
                  }, 1500);
                } else {
                  throw new Error(submitRes.data?.msg || '第二步提交审核失败');
                }
              } else {
                throw new Error(editRes.data?.msg || '第一步编辑项目失败');
              }
      } catch (error) {
        console.error('提交审核失败:', error);
        uni.showToast({
          title: error.message || '提交审核失败',
          icon: 'none'
        });
      } finally {
        uni.hideLoading();
      }
    },
    
    // 标记为异常
    markAsException() {
      uni.showModal({
        title: '确认标记',
        content: '确定要将此项目标记为异常吗？',
        success: (res) => {
          if (res.confirm) {
            // 这里可以调用标记异常的接口
            uni.showToast({
              title: '已标记为异常',
              icon: 'success'
            });
            
            // 延迟返回上一页
            setTimeout(() => {
              uni.navigateBack();
            }, 1500);
          }
        }
      });
    },

    // 标记收款计划为异常
    markPlanAsException(plan, index) {
      uni.showModal({
        title: '确认标记',
        content: `确定要将此收款计划标记为异常吗？`,
        success: async (res) => {
          if (res.confirm) {
            try {
              uni.showLoading({ title: '标记中...' });
              const markRes = await uni.request({
                url: 'https://data.web1995.top/api/project/setProjectPlan',
                method: 'POST',
                data: {
                  id: plan.id, // 当前收款计划这条数据的id
                  pid: this.projectId // 项目id
                },
                header: {
                  'token': uni.getStorageSync('sc-token') || ''
                }
              });
              console.log('setProjectPlan接口返回:', markRes);
              if (markRes.data && markRes.data.code === 1) {
                this.paymentPlans[index].status = '异常';
                uni.showToast({
                  title: '已标记为异常',
                  icon: 'success'
                });
                this.getProjectPlanList(); // 刷新列表以更新状态
              } else {
                throw new Error(markRes.data?.msg || '标记失败');
              }
            } catch (error) {
              console.error('标记收款计划异常失败:', error);
              uni.showToast({
                title: error.message || '标记失败',
                icon: 'none'
              });
            } finally {
              uni.hideLoading();
            }
          }
        }
      });
    },
    
    // 格式化时间戳
    formatDate(timestamp) {
      if (!timestamp) return '';
      const date = new Date(timestamp * 1000);
      return date.toLocaleDateString('zh-CN');
    },
    
  }
}
</script>

<style lang="scss" scoped>
.detail-page {
  min-height: 100vh;
  background: #f5f6fa;
  padding: 30rpx;
  padding-bottom: 120rpx; /* 为固定按钮留出空间 */
  box-sizing: border-box;
}



.info-card, .payment-plan-card {
  background: #fff;
  border-radius: 16rpx;
  padding: 30rpx;
  margin-bottom: 20rpx;
  box-shadow: 0 4rpx 8rpx rgba(0, 0, 0, 0.05);
}

.contract-section, .settlement-section, .payment-plan-section {
  margin-bottom: 30rpx;
}

.contract-section:last-child, .settlement-section:last-child {
  margin-bottom: 0;
}

.section-title {
  font-size: 28rpx;
  font-weight: 600;
  color: #333;
  margin-bottom: 20rpx;
  padding-bottom: 12rpx;
  border-bottom: 1rpx solid #f0f0f0;
}

.contract-form {
  display: flex;
  flex-direction: column;
  gap: 20rpx;
}

.contract-form .form-item {
  display: flex;
  flex-direction: column;
  gap: 8rpx;
}

.contract-form .form-label {
  font-size: 24rpx;
  color: #999;
}

/* 收款计划样式 */
.payment-plan-section {
  background: #f8f9fa;
  border-radius: 12rpx;
  padding: 20rpx;
}

.plan-list {
  margin-bottom: 20rpx;
}

.plan-item {
  background: #fff;
  border-radius: 8rpx;
  padding: 16rpx;
  margin-bottom: 12rpx;
  border: 1rpx solid #e9ecef;
}

.plan-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12rpx;
}

.plan-number {
  font-size: 26rpx;
  font-weight: 600;
  color: #333;
}

.plan-status {
  font-size: 22rpx;
  padding: 4rpx 12rpx;
  border-radius: 12rpx;
  background: #e6f7ff;
  color: #409eff;
}

.plan-status.pending {
  background: #fff7e6;
  color: #fa8c16;
}

.plan-status.completed {
  background: #f6ffed;
  color: #52c41a;
}

/* 收款计划信息区域 */
.plan-info {
  margin-bottom: 20rpx;
}

.plan-info .info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24rpx;
}

.plan-info .info-item {
  display: flex;
  flex-direction: column;
  gap: 12rpx;
}

.plan-info .info-label {
  font-size: 22rpx;
  color: #666;
  font-weight: 500;
  text-align: left;
}

.plan-info .info-value {
  font-size: 24rpx;
  color: #333;
  font-weight: 600;
  min-height: 48rpx;
  display: flex;
  align-items: center;
  padding: 0 4rpx;
}



/* 金额高亮样式 */
.amount-highlight {
  background: #f0f9ff;
  color: #0ea5e9;
  padding: 12rpx 16rpx;
  border-radius: 8rpx;
  font-weight: 900;
  min-height: 48rpx;
  display: flex;
  align-items: center;
}

.received-highlight {
  background: #f6ffed;
  color: #52c41a;
  padding: 12rpx 16rpx;
  border-radius: 8rpx;
  font-weight: 900;
  min-height: 48rpx;
  display: flex;
  align-items: center;
}



/* 操作按钮区域 */
.plan-actions {
  display: flex;
  gap: 12rpx;
  margin-top: 20rpx;
  padding-top: 16rpx;
  border-top: 1rpx solid #f0f0f0;
}

.action-btn {
  flex: 1;
  height: 60rpx;
  font-size: 26rpx;
  border-radius: 8rpx;
  border: none;
  background: #f5f5f5;
  color: #666;
  display: flex;
  align-items: center;
  justify-content: center;
}

.action-btn.edit {
  background: #e6f7ff;
  color: #409eff;
}

.action-btn.delete {
  background: #fff2f0;
  color: #ff4d4f;
}

.action-btn.delete.disabled {
  background: #f5f5f5;
  color: #ccc;
  cursor: not-allowed;
}

.action-btn.exception {
  background: #fff2f0;
  color: #ff4d4f;
}

.action-btn.detail {
  background: #f0f9ff;
  color: #0ea5e9;
}

.empty-plans {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 200rpx;
  padding: 40rpx 20rpx;
  text-align: center;
}

.empty-text {
  font-size: 26rpx;
  color: #999;
}

/* 收款计划总结样式 */
.plan-summary {
  background: #f8f9fa;
  border-radius: 12rpx;
  padding: 20rpx;
  margin: 20rpx 0;
  border: 1rpx solid #e9ecef;
}

.summary-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12rpx 0;
  border-bottom: 1rpx solid #f0f0f0;
}

.summary-item:last-child {
  border-bottom: none;
}

.summary-label {
  font-size: 26rpx;
  color: #666;
  font-weight: 500;
}

.summary-value {
  font-size: 28rpx;
  color: #333;
  font-weight: 600;
}

.summary-value.highlight {
  color: #52c41a;
  font-weight: bold;
  font-size: 32rpx;
}

.add-plan-btn {
  flex: 1;
  background: #409eff;
  color: #fff;
  border: none;
  border-radius: 8rpx;
  padding: 12rpx;
  font-size: 28rpx;
  margin-top: 16rpx;
}

.plan-actions {
  display: flex;
  gap: 20rpx;
  margin-top: 16rpx;
}

.exception-btn {
  flex: 1;
  background: #ff4d4f;
  color: #fff;
  border: none;
  border-radius: 8rpx;
  padding: 12rpx;
  font-size: 28rpx;
  margin-top: 16rpx;
}

.view-plans-btn {
  flex: 1;
  background: #409eff;
  color: #fff;
  border: none;
  border-radius: 8rpx;
  padding: 12rpx;
  font-size: 28rpx;
  margin-top: 16rpx;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20rpx;
  padding-bottom: 20rpx;
  border-bottom: 1rpx solid #f0f0f0;
}

.card-title {
  font-size: 32rpx;
  font-weight: bold;
  color: #333;
}

.add-btn {
  background: #409eff;
  color: #fff;
  border: none;
  border-radius: 8rpx;
  padding: 8rpx 20rpx;
  font-size: 24rpx;
  height: 56rpx;
  line-height: 40rpx;
}

.info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20rpx;
}

.info-item {
  display: flex;
  flex-direction: column;
  gap: 8rpx;
}

.label {
  font-size: 24rpx;
  color: #999;
}

.value {
  font-size: 28rpx;
  color: #333;
  font-weight: 500;
}

.value.highlight {
  color: #409eff;
  font-weight: bold;
}

.status-badge {
  padding: 4rpx 12rpx;
  border-radius: 12rpx;
  font-size: 24rpx;
  text-align: center;
  width: fit-content;
}

.status-active {
  background: #e6f7ff;
  color: #409eff;
}

.status-completed {
  background: #f6ffed;
  color: #52c41a;
}

.status-error {
  background: #fff2e8;
  color: #fa8c16;
}

.status-finished {
  background: #f6ffed;
  color: #52c41a;
}

.plan-list {
  display: flex;
  flex-direction: column;
  gap: 16rpx;
}

.plan-item {
  background: #fafafa;
  border-radius: 12rpx;
  padding: 20rpx;
  border: 1rpx solid #f0f0f0;
}

.plan-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16rpx;
}

.plan-number {
  font-size: 28rpx;
  font-weight: bold;
  color: #333;
}

.plan-status {
  font-size: 24rpx;
  padding: 4rpx 12rpx;
  border-radius: 8rpx;
}

.plan-status.pending {
  background: #fff7e6;
  color: #fa8c16;
}

.plan-status.completed {
  background: #f6ffed;
  color: #52c41a;
}

.plan-status.success {
  background: #f6ffed;
  color: #52c41a;
}

.plan-status.error {
  background: #fff2f0;
  color: #ff4d4f;
}

.plan-status.overdue {
  background: #fff7e6;
  color: #fa8c16;
}

.plan-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.plan-info {
  display: flex;
  flex-direction: column;
  gap: 8rpx;
}

.amount {
  font-size: 32rpx;
  font-weight: bold;
  color: #409eff;
}

.date {
  font-size: 24rpx;
  color: #666;
}

.plan-actions {
  display: flex;
  gap: 12rpx;
}

.action-btn {
  background: #f5f5f5;
  color: #666;
  border: none;
  border-radius: 6rpx;
  padding: 8rpx 16rpx;
  font-size: 22rpx;
}

.action-btn.edit {
  background: #e6f7ff;
  color: #409eff;
}

.action-btn.delete {
  background: #fff2e8;
  color: #fa8c16;
}

.action-btn.detail {
  background: #f0f9ff;
  color: #0ea5e9;
}

.empty-plans {
  text-align: center;
  padding: 60rpx 0;
}

.empty-text {
  color: #999;
  font-size: 28rpx;
}

/* 弹窗样式 */
.add-plan-modal {
  background: #fff;
  border-radius: 16rpx;
  width: 600rpx;
  max-height: 80vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 30rpx;
  border-bottom: 1rpx solid #f0f0f0;
  flex-shrink: 0;
}

.modal-title {
  font-size: 32rpx;
  font-weight: bold;
  color: #333;
}

.close-btn {
  font-size: 40rpx;
  color: #999;
  cursor: pointer;
}

.modal-content {
  padding: 30rpx;
  flex: 1;
  overflow-y: auto;
  max-height: calc(80vh - 200rpx);
}

/* 自定义滚动条样式 */
.modal-content::-webkit-scrollbar {
  width: 8rpx;
}

.modal-content::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: 4rpx;
}

.modal-content::-webkit-scrollbar-thumb {
  background: #c1c1c1;
  border-radius: 4rpx;
}

.modal-content::-webkit-scrollbar-thumb:hover {
  background: #a8a8a8;
}

.form-item {
  margin-bottom: 24rpx;
}

.form-label {
  display: block;
  font-size: 28rpx;
  color: #333;
  margin-bottom: 12rpx;
}

.form-input {
  width: 100%;
  height: 80rpx;
  border: 1rpx solid #e0e0e0;
  border-radius: 8rpx;
  padding: 0 20rpx;
  font-size: 28rpx;
  box-sizing: border-box;
}

.date-picker {
  width: 100%;
  height: 80rpx;
  border: 1rpx solid #e0e0e0;
  border-radius: 8rpx;
  display: flex;
  align-items: center;
  padding: 0 20rpx;
  box-sizing: border-box;
}

.picker-text {
  font-size: 28rpx;
  color: #333;
}

.upload-section {
  width: 100%;
}

.upload-btn {
  width: 100%;
  height: 120rpx;
  border: 2rpx dashed #d9d9d9;
  border-radius: 8rpx;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8rpx;
}

.upload-icon {
  font-size: 40rpx;
  color: #d9d9d9;
}

.upload-text {
  font-size: 24rpx;
  color: #999;
}

.image-preview {
  position: relative;
  width: 100%;
}

.preview-img {
  width: 100%;
  height: 200rpx;
  border-radius: 8rpx;
}

/* 多张图片显示样式 */
.image-list {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16rpx;
}

.image-item {
  position: relative;
  width: 100%;
}

.image-item .preview-img {
  width: 100%;
  height: 160rpx;
  border-radius: 8rpx;
  object-fit: cover;
}

.upload-btn.add-more {
  width: 100%;
  height: 160rpx;
  border: 2rpx dashed #d9d9d9;
  border-radius: 8rpx;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8rpx;
  background: #fafafa;
}

.remove-btn {
  position: absolute;
  top: -10rpx;
  right: -10rpx;
  width: 40rpx;
  height: 40rpx;
  background: #ff4d4f;
  color: #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24rpx;
}

.modal-actions {
  display: flex;
  gap: 20rpx;
  padding: 30rpx;
  border-top: 1rpx solid #f0f0f0;
  flex-shrink: 0;
}

.modal-btn {
  flex: 1;
  height: 80rpx;
  border-radius: 8rpx;
  font-size: 28rpx;
  border: none;
}

.modal-btn.cancel {
  background: #f5f5f5;
  color: #666;
}

.modal-btn.confirm {
  background: #409eff;
  color: #fff;
}

.action-buttons {
  display: flex;
  gap: 20rpx;
  margin-top: 30rpx;
}

.btn {
  flex: 1;
  height: 80rpx;
  border-radius: 12rpx;
  font-size: 28rpx;
  border: none;
}

.btn.primary {
  background: #409eff;
  color: #fff;
}

.btn.secondary {
  background: #f5f5f5;
  color: #666;
}

.btn.load-data {
  background: #52c41a;
  color: #fff;
}



.form-value {
  font-size: 28rpx;
  color: #333;
  font-weight: 500;
}

.net-income {
  color: #52c41a;
  font-weight: bold;
  font-size: 32rpx;
}

.unpaid-amount {
  color: #ff4d4f;
  font-weight: bold;
  font-size: 32rpx;
}

.uninvoiced-amount {
  color: #fa8c16;
  font-weight: bold;
  font-size: 32rpx;
}

.auto-calc-tip {
  color: #999;
  font-size: 20rpx;
  font-weight: normal;
}

/* 固定在底部的提交按钮 */
.fixed-submit-btn {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: #fff;
  padding: 20rpx 30rpx;
  box-shadow: 0 -4rpx 12rpx rgba(0, 0, 0, 0.1);
  z-index: 1000;
}

.submit-audit-btn {
  width: 100%;
  height: 80rpx;
  background: #52c41a;
  color: #fff;
  border: none;
  border-radius: 12rpx;
  font-size: 32rpx;
  font-weight: bold;
  display: flex;
  align-items: center;
  justify-content: center;
}

.submit-audit-btn:active {
  background: #389e0d;
  transform: scale(0.98);
}

/* 禁用状态样式 */
.disabled-input {
  background-color: #f5f5f5 !important;
  color: #999 !important;
  cursor: not-allowed !important;
}

.disabled-upload {
  background-color: #f5f5f5 !important;
  color: #999 !important;
  cursor: not-allowed !important;
  border-color: #d9d9d9 !important;
}

.action-btn.disabled {
  background-color: #f5f5f5 !important;
  color: #ccc !important;
  cursor: not-allowed !important;
}

.add-plan-btn.disabled {
  background-color: #f5f5f5 !important;
  color: #ccc !important;
  cursor: not-allowed !important;
}
</style> 